

var xmlHttpRequest;
function createXMLHttpRequest()
{
    if (window.XMLHttpRequest) //非IE浏览器
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveObject)//IE6以上版本的IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Msxml2.XMLHTTP");
    }
    else //IE6及以下版本IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Microsoft.XMLHTTP");
    }
}

function updateCart(itemId) {

    var quantity=document.getElementById("quantity").value;
        if(quantity == 1){
            sendRequestRemove("/cart/remove?workingItemId="+itemId);
        }else{
            sendRequest("/cart/updateCart?quantity="+ quantity);
        }
}


function sendRequest(url) {
    createXMLHttpRequest();
    xmlHttpRequest.open("GET", url, true);
    xmlHttpRequest.onreadystatechange = processResponse;
    xmlHttpRequest.send(null);
}


function processResponse() {
    if (xmlHttpRequest.readyState == 4) {
        if (xmlHttpRequest.status == 200) {
            var resp = xmlHttpRequest.responseText;
            var array = resp.split(",");

            document.getElementById("quantity").innerText=array[0];
            document.getElementById("total").innerText = array[1];
            document.getElementById("subtotal").innerText = array[2];
        }
    }
}
